local _Color = Class("Color", Vect)
Color32 = {}

function Color32.new(r, g, b, a)
    if type(r) == "table" then
        r, g, b, a = unpack(r)
    end
    a = a or 255
    return _Color.new(r / 255, g / 255, b / 255, a / 255)
end

Color = setmetatable({
    __gets = {
        white = function()
            return Color32.new(255, 255, 255, 255)
        end,
        black = function()
            return Color32.new(0, 0, 0, 255)
        end,
        red = function()
            return Color32.new(255, 0, 0, 255)
        end,
        green = function()
            return Color32.new(0, 255, 0, 255)
        end,
        blue = function()
            return Color32.new(0, 0, 255, 255)
        end,
        yellow = function()
            return Color32.new(255, 255,0, 255)
        end,
        lightBlue = function()
            return Color32.new(0, 255, 255, 255)
        end,
        darkBlue = function()
            return Color32.new(0, 0, 128, 255)
        end,
        darkGreen = function()
            return Color32.new(0, 128, 0, 255)
        end,
        darkRed = function()
            return Color32.new(128, 0, 0, 255)
        end,
        pink = function()
            return Color32.new(255, 192, 203, 255)
        end,
        gray = function()
            return Color32.new(128, 128, 128, 255)
        end,
        lightGray = function()
            return Color32.new(211, 211, 211, 255)
        end,
        zero = function ()
            return Color.new(0, 0, 0, 0)
        end
    },
    __sets = {}
}, MetaTable.get_set)
function Color.new(...)
    return _Color.new(...)
end

function Color.fromHex(hex)
    local hex = hex:gsub("#","") -- 移除十六进制颜色中的'#'
    return Color32.new(
        tonumber("0x"..hex:sub(1,2)),
        tonumber("0x"..hex:sub(3,4)),
        tonumber("0x"..hex:sub(5,6)),
        #hex == 8 and tonumber("0x"..hex:sub(7,8)) or 255
    )
end

---@diagnostic disable-next-line: duplicate-set-field
function _Color:ctor(...)
    Vect.ctor(self, ...)
end

function _Color:__sub(t)
    return Vect.__sub(self, t)
end

function _Color:__add(t)
    return Vect.__add(self, t)
end

function _Color:__mul(t)
    return Vect.__mul(self, t)
end

function _Color:__div(t)
    return Vect.__div(self, t)
end

function _Color:unpack()
    return self[1], self[2], self[3], self[4]
end

function _Color:rgba()
    return self:unpack()
end

function _Color:__tostring()
    return string.format("Color(%f, %f, %f, %f)", self[1], self[2], self[3], self[4])
end

_Color.defineProp("r", {
    get = function(inst)
        return inst[1]
    end
})

_Color.defineProp("g", {
    get = function(inst)
        return inst[2]
    end
})

_Color.defineProp("b", {
    get = function(inst)
        return inst[3]
    end
})

_Color.defineProp("a", {
    get = function(inst)
        return inst[4]
    end
})